<%@ page import="hc.uco.Paciente" %>
<%@ page import="hc.uco.Medicacao" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'paciente.label', default: 'Paciente')}" />
        <title><g:message code="default.show.label" args="[entityName]" /></title>
    </head>
    <body>
        <g:render template="/mainbar" />
        <div class="body">
            <h1>Paciente: ${fieldValue(bean: pacienteInstance, field: "nome")}</h1>
            <g:render template="/pacientebar" />
            <div class="dialog">
                <g:render template="/pacienteheader" />
                <g:if test="${flash.message}"><div class="message">${flash.message}</div></g:if>
                <h2><g:message code="medicacao.domiciliar.titulo" /></h2>
	            <g:hasErrors bean="${medicacaoInstance}">
	            <div class="errors">
	                <g:renderErrors bean="${medicacaoInstance}" as="list" />
	            </div>
	            <g:if test="${medicacaoInstance.tipo == 'dom'}">
				     <g:set var="medicacaoInstanceDom" value="${medicacaoInstance}" />
				</g:if>
            	<g:if test="${medicacaoInstance.tipo == '24h'}">
				     <g:set var="medicacaoInstance24h" value="${medicacaoInstance}" />
				</g:if>
            	</g:hasErrors>
            	
                <div class="list">
                <table class="medicacao">
                    <thead>
                        <tr>
                            <th width="60%">${message(code: 'medicacao.principioAtivo.label', default: 'Principio Ativo')} </th>
                            <th nowrap="nowrap" width="30%">${message(code: 'medicacao.dose.label', default: 'Dose')} (${message(code: 'medicacao.unidade')})</th>
                            <th width="20px"> </th>
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${medicacaoInstanceList}" status="i" var="medicacaoInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                            <td>${fieldValue(bean: medicacaoInstance, field: "principioAtivo")}</td>
                            <td nowrap="nowrap">${fieldValue(bean: medicacaoInstance, field: "dose")}</td>
                            <g:if test="${session.usuario.admin}">
                            <td><g:link class="delete" action="delete" controller="medicacao" id="${medicacaoInstance?.id}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');"><img src="${resource(dir:'images/skin',file:'database_delete.png')}" alt="Excluir medica��o" border="0" /></g:link></td>
                        	</g:if>
                        </tr>
                    </g:each>
                    <g:form action="save" >
                    	<g:hiddenField name="paciente.id" value="${pacienteInstance?.id}" />
                    	<g:hiddenField name="tipo" value="dom" />
                    	<tr class="prop" class='even'>
                    		<td valign="top" class=" ${hasErrors(bean: medicacaoInstanceDom, field: 'principioAtivo', 'errors')} ">
                                 <g:textField name="principioAtivo" value="${medicacaoInstanceDom?.principioAtivo}" size="30"/>
                            </td>
                            <td valign="top" class=" ${hasErrors(bean: medicacaoInstanceDom, field: 'dose', 'errors')}" nowrap="nowrap">
                                <g:textField name="dose" value="${medicacaoInstanceDom?.dose}" size="5"/>
                            </td>
                            <td valign="top" class="value">
                                <div class="buttons">
				                    <span class="button"><g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /></span>
				                </div>
                            </td>
                        </tr>
                    </g:form>
                    </tbody>
                </table>
                </div>
                <h2><g:message code="medicacao.24h.titulo" /></h2>
                <div class="list">
                <table class="medicacao">
                    <thead>
                        <tr>
                            <th width="60%">${message(code: 'medicacao.principioAtivo.label', default: 'Principio Ativo')} </th>
                            <th nowrap="nowrap" width="30%">${message(code: 'medicacao.dose.label', default: 'Dose')} (${message(code: 'medicacao.unidade')})</th>
                            <th width="20px"> </th>
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${medicacao24hInstanceList}" status="i" var="medicacao24hInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                            <td>${fieldValue(bean: medicacao24hInstance, field: "principioAtivo")}</td>
                            <td nowrap="nowrap">${fieldValue(bean: medicacao24hInstance, field: "dose")} </td>
                            <td><g:link class="delete" action="delete" controller="medicacao" id="${medicacao24hInstance?.id}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');"><img src="${resource(dir:'images/skin',file:'database_delete.png')}" alt="Excluir medica��o" border="0" /></g:link></td>
                        </tr>
                    </g:each>
                    <g:form action="save" >
                    	<g:hiddenField name="paciente.id" value="${pacienteInstance?.id}" />
                    	<g:hiddenField name="tipo" value="24h" />
                    	<tr class="prop" class='even'>
                    		<td valign="top" class=" ${hasErrors(bean: medicacaoInstance24h, field: 'principioAtivo', 'errors')} ">
                                 <g:textField name="principioAtivo" value="${medicacaoInstance24h?.principioAtivo}" size="30" />
                            </td>
                            <td valign="top" class=" ${hasErrors(bean: medicacaoInstance24h, field: 'dose', 'errors')}" nowrap="nowrap">
                                <g:textField name="dose" value="${medicacaoInstance24h?.dose}" size="5"/> 
                            </td>
                            <td valign="top" class="value">
                                <div class="buttons">
				                    <span class="button"><g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /></span>
				                </div>
                            </td>
                        </tr>
                    </g:form>
                    </tbody>
                </table>
                </div>
        </div>
    </body>
</html>

